home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gempp19.zoo / gem++19 / src / gemscro.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-05  |  3.2 KB  |  120 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemc.h"
  12. #include "grect.h"
  13.  
  14. static int abs(int i)
  15. {
  16.     return i<0 ? -i : i;
  17. }
  18.  
  19. static const int UNLIMITED=-1;
  20.  
  21. GEMscrollableobject::GEMscrollableobject(GEMform& form, int RSCindex) :
  22.     VDI(),
  23.     GEMuserobject(form,RSCindex)
  24. {
  25. }
  26.  
  27. void GEMscrollableobject::Scroll(int pixels_right, int pixels_down)
  28. {
  29.     if (pixels_down || pixels_right) {
  30.         int X,Y;
  31.         GetAbsoluteXY(X,Y);
  32.  
  33.         for (GRect* clip=form.FirstClip(myindex); clip; clip=form.NextClip(clip)) {
  34.             int pxy[8];
  35.  
  36.             // Anything to scroll?
  37.             if (abs(pixels_right)<clip->g_w
  38.              && abs(pixels_down)<clip->g_h) {
  39.                 if (pixels_right>0) {
  40.                     pxy[0]=clip->g_x+pixels_right;
  41.                     pxy[2]=clip->g_x+clip->g_w-1;
  42.                     pxy[4]=clip->g_x;
  43.                     pxy[6]=clip->g_x+clip->g_w-pixels_right-1;
  44.                 } else {
  45.                     pxy[0]=clip->g_x;
  46.                     pxy[2]=clip->g_x+clip->g_w+pixels_right-1;
  47.                     pxy[4]=clip->g_x-pixels_right;
  48.                     pxy[6]=clip->g_x+clip->g_w-1;
  49.                 }
  50.  
  51.                 if (pixels_down>0) {
  52.                     pxy[1]=clip->g_y+pixels_down;
  53.                     pxy[3]=clip->g_y+clip->g_h-1;
  54.                     pxy[5]=clip->g_y;
  55.                     pxy[7]=clip->g_y+clip->g_h-pixels_down-1;
  56.                 } else {
  57.                     pxy[1]=clip->g_y;
  58.                     pxy[3]=clip->g_y+clip->g_h+pixels_down-1;
  59.                     pxy[5]=clip->g_y-pixels_down;
  60.                     pxy[7]=clip->g_y+clip->g_h-1;
  61.                 }
  62.  
  63.                 ro_cpyfm(VDI::SRC,pxy);
  64.  
  65.                 if (pixels_right>0) {
  66.                     GRect redraw_side(clip->g_x+clip->g_w-pixels_right,clip->g_y,
  67.                         pixels_right,clip->g_h);
  68.                     RedrawClipped(X,Y,redraw_side);
  69.                 } else if (pixels_right) {
  70.                     GRect redraw_side(clip->g_x,clip->g_y,-pixels_right,clip->g_h);
  71.                     RedrawClipped(X,Y,redraw_side);
  72.                 }
  73.  
  74.                 if (pixels_down>0) {
  75.                     if (pixels_right>0) {
  76.                         GRect redraw_side(clip->g_x,clip->g_y+clip->g_h-pixels_down,
  77.                             clip->g_w-pixels_right,pixels_down);
  78.                         RedrawClipped(X,Y,redraw_side);
  79.                     } else {
  80.                         GRect redraw_side(clip->g_x-pixels_right,clip->g_y+clip->g_h-pixels_down,
  81.                             clip->g_w+pixels_right,pixels_down);
  82.                         RedrawClipped(X,Y,redraw_side);
  83.                     }
  84.                 } else if (pixels_down) {
  85.                     if (pixels_right>0) {
  86.                         GRect redraw_side(clip->g_x,clip->g_y,clip->g_w-pixels_right,-pixels_down);
  87.                         RedrawClipped(X,Y,redraw_side);
  88.                     } else {
  89.                         GRect redraw_side(clip->g_x-pixels_right,clip->g_y,clip->g_w+pixels_right,-pixels_down);
  90.                         RedrawClipped(X,Y,redraw_side);
  91.                     }
  92.                 }
  93.             } else {
  94.                 RedrawClipped(X,Y,*clip);
  95.             }
  96.         }
  97.     }
  98. }
  99.  
  100. void GEMscrollableobject::VScroll(int pixels_down)
  101. {
  102.     // Could be marginally optimized by specificizing Scroll().
  103.     Scroll(0,pixels_down);
  104. }
  105.  
  106. void GEMscrollableobject::HScroll(int pixels_right)
  107. {
  108.     // Could be marginally optimized by specificizing Scroll().
  109.     Scroll(pixels_right,0);
  110. }
  111.  
  112. void GEMscrollableobject::Draw(const PARMBLK* p)
  113. {
  114.     GRect drawclip(p->pb_xc,p->pb_yc,p->pb_wc,p->pb_hc);
  115.     GRect objclip(p->pb_x,p->pb_y,GEMuserobject::Width(),GEMuserobject::Height());
  116.     drawclip.Clip(objclip);
  117.  
  118.     RedrawClipped(p->pb_x,p->pb_y,drawclip);
  119. }
  120.